package com.hall.item.item.mq;

import com.hall.item.item.constans.MqConstants;
import com.hall.item.item.service.impl.SearchServiceImpl;
import org.elasticsearch.search.SearchService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class HmallListener {

    @Autowired
    private SearchServiceImpl searchService;

    /**
     * 监听商品新增或修改的业务
     *
     * @param id
     */
    @RabbitListener(queues = MqConstants.HMALL_INSERT_QUEUE)
    public void listenHmallInsertOrUpdate(Long id) {
        searchService.insertById(id);
    }

    /**
     * 监听商品删除的业务
     *
     * @param id
     */
    @RabbitListener(queues = MqConstants.HMALL_DELETE_QUEUE)
    public void listenHmallDeleteOrUpdate(Long id) {
        searchService.deleteById(id);
    }
}
